#include "stdio.h"
#include "string.h"

struct date
{
    int year;
    int month;
    int day;
};

struct score
{
    int math;
    int english;
    int chinese;
};

struct student
{
    int id;
    char name[20];
    struct date birthday;
    struct score myScore;
    struct student *next;
};

typedef struct student Student;

void changeScore(struct student *ps)
{
    ps->myScore.math +=10;
    ps->myScore.english +=10;
    ps->myScore.chinese +=10;
}


int main(){
    struct student s1;

    struct student *ps = &s1;
    ps->id = 2024;
    strcpy(ps->name, "zhibo");
    ps->birthday = (struct date){2024, 10, 3};

    printf("id = %d, name = %s\n", ps->id, ps->name);
    printf("id = %d, name = %s\n", s1.id, s1.name);
    printf("birthday = %d-%d-%d\n", ps->birthday.year, ps->birthday.month, ps->birthday.day);

    printf("*********************\n");

    struct student s2[3] = {
        {1024, "zhibo", 2023, 9, 5},
        {1025, "zhibo", {2023, 8, 6}},
        {1026, "zhibo", {2023, 7, 7}}
    };

    for(int i = 0; i < 3; ++i){
        printf("id = %d, name = %s\n", s2[i].id, s2[i].name);
        printf("birthday = %d-%d-%d\n", s2[i].birthday.year, s2[i].birthday.month, s2[i].birthday.day);
        printf("\n");
    }

    printf("%lu\n", sizeof(s2[0]));
    printf("%lu\n", sizeof(s2));
    printf("%lu\n", sizeof(struct student));
    printf("%lu\n", sizeof(Student));

    printf("*********************\n");
    struct student s3 = {1027, "lisi", {2023, 6, 8}, {100, 98, 7}};
    struct student *ps3 = &s3;
    changeScore(ps3);
    printf("id = %d, name = %s\n", ps3->id, ps3->name);
    printf("math = %d, english = %d, chinese = %d\n", ps3->myScore.math, ps3->myScore.english, ps3->myScore.chinese);

    printf("*********************\n");
    struct student s4, s5, s6;

    s4 = (struct student){1028, "zhibo4", {2023, 5, 9}, {76, 87, 95}, &s5};
    s5 = (struct student){1029, "zhibo5", {2023, 4, 10}, {86, 77, 65}, &s6};
    s6 = (struct student){1030, "zhibo6", {2023, 3, 11}, {96, 87, 75}, NULL};

    struct student *ps4 = &s4;
    struct student *ps5 = &s5;
    struct student *ps6 = &s6;

    struct student *pp = ps4;

    while(pp != NULL){
        printf("id = %d, name = %s\n", pp->id, pp->name);
        pp = pp->next;
    }

    printf("-------------------------\n");

    struct student s7 = {1031, "zhibo7", {2023, 2, 12}, {65, 74, 89}};
    struct student *ps7 = &s7;
    pp = ps4;
    while(pp->next != NULL){
        pp = pp->next;
    }
    pp->next = ps7;

    pp = ps4;

    while(pp != NULL){
        printf("id = %d, name = %s\n", pp->id, pp->name);
        pp = pp->next;
    }

    printf("*********************\n");





    return 0;
}